<!DOCTYPE html>
<html>
<head>
    <title>购房人列表</title>
<#include "../common/common.ftl"/>
</head>
<body>
<div class="layui-fluid">
    <blockquote class="layui-elem-quote layui-bg-white">
        协议信息：【姓名：<span class="jmdf-color-red">${(contract.name)!}</span>】【协议编号：<span
            class="jmdf-color-red">${(contract.contractCode)!}</span>】
    <#if (houseId != 0)>房源信息：【安置项目：<span class="jmdf-color-red">${(house.azProject.projectName)!}</span>】【幢号：<span
            class="jmdf-color-red">${(house.buildNum)!}</span>】【户号：<span
            class="jmdf-color-red">${(house.houseNum)!}</span>】</#if>
    <#if (carLotId != 0)>车位信息：【安置项目：<span class="jmdf-color-red">${(carLot.azProject.projectName)!}</span>】【幢号：<span
            class="jmdf-color-red">${(carLot.buildNum)!}</span>】【户号：<span
            class="jmdf-color-red">${(carLot.houseNum)!}</span>】</#if>
        <#if (shopHouseId != 0)>店面信息：【安置项目：<span class="jmdf-color-red">${(shopHouse.azProject.projectName)!}</span>】【幢号：<span
                class="jmdf-color-red">${(shopHouse.buildNum)!}</span>】【户号：<span
                class="jmdf-color-red">${(shopHouse.houseNum)!}</span>】</#if>
    </blockquote>
    <div class="layui-row  layui-col-space10">
        <div class="layui-col-xs12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <table id="dataTable" class="layui-table" lay-filter="layFilter"></table>
                    <!--序号-->
                    <script type="text/html" id="indexTpl">
                        {{d.LAY_TABLE_INDEX+1}}
                    </script>
                    <!--菜单-->
                    <script type="text/html" id="dataTable_toolbar">
                        <a class="layui-btn layui-btn-xs jmdf-btn-edit" lay-event="dataTable_edit"><i
                                class="layui-icon layui-icon-edit"></i>修改</a>
                        <a class="layui-btn layui-btn-xs jmdf-btn-delete" lay-event="dataTable_delete"><i
                                class="layui-icon layui-icon-delete"></i>删除</a>
                    </script>
                    <!-- 表格头部工具栏 -->
                    <script type="text/html" id="toolbar">
                        <div class="layui-btn-container right">
                            <button lay-event="reload" class="layui-btn layui-btn-sm"><i
                                    class="layui-icon layui-icon-refresh"></i>重载
                            </button>
                            <button lay-event="add" class="layui-btn layui-btn-sm"><i
                                    class="layui-icon layui-icon-add-circle"></i>新增
                            </button>
                            <button lay-event="setBuyHousePerson" class="layui-btn layui-btn-sm setBuyHousePerson"><i
                                    class="layui-icon layui-icon-edit"></i>设置为产权人
                            </button>
                        </div>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/layui/layui.js" charset="utf-8"></script>
<script>
    layui.config({
        base: '/modules/' //静态资源所在路径
    }).use(['table', 'form', 'jquery', 'jmdf', 'page'], function () {
        var $ = layui.jquery, jmdf = layui.jmdf, page = layui.page, table = layui.table, form = layui.form, parentIndex = parent.layer.getFrameIndex(window.name);
        form.render();
        /***********************table表格相关操作 start*************************/
        var tableRenderId = "renderId";
        var tableId = "dataTable";
        var table_layFilter = "layFilter";
        var tableUrl = "loadChooseBuyPersonList?contractId=" + ${(contract.id)!"0"}+"&houseId=" + ${houseId} +"&carLotId=" + ${carLotId}+"&storageRoomId=" + ${storageRoomId} +"&shopHouseId=" + ${shopHouseId};

        //列项内容
        var cols = [[
            {checkbox: true, fixed: true, field: "LAY_CHECKED"}
            , {title: "序号", toolbar: '#indexTpl', type: "numbers", fixed: 'left', align: 'center', width: 60}
            , {field: "buyHousePersonName", title: "产权人姓名", align: 'center', minWidth: 200}
            , {field: "idCard", title: "产权人身份证号", align: 'center', minWidth: 180}
            , {field: "tel", title: "产权人联系方式", align: 'center', minWidth: 150}
            , {title: '操作', fixed: 'right', align: 'center', toolbar: '#dataTable_toolbar', minWidth: 220}
        ]];
        //table设置项
        var options = {
            elem: '#' + tableId//table列表id值
            , url: tableUrl
            , toolbar: '#toolbar'//自定义工具栏
            , cols: cols
            , id: tableRenderId
            , defaultToolbar: ['filter', 'print']//显示列、打印
            , autoSort: false //禁用前端自动排序。
        };

        //初始表格（含分页设置）
        page.render(options);
        //表格排序
        page.sort(tableId, tableRenderId);
        //刷新当前页方法封装
        page.reload();

        //分页查询（查询条件）
        $("#searchButton").click(function () {
            page.search("searchForm", tableRenderId);
        });

        //头工具栏事件
        table.on('toolbar(' + table_layFilter + ')', function (obj) {
            switch (obj.event) {
                case 'reload':
                    loadData();
                    break;
                case 'add':
                    jmdf.form("chooseBuyPersonForm?contractId=" + ${(contract.id)!"0"});
                    break;
                case 'setBuyHousePerson':
                    setBuyHousePersonData();
                    break;
            }
        });

        table.on("tool(" + table_layFilter + ")", function (obj) {
            var data = obj.data;///获得当前行数据
            var layEvent = obj.event;//获得lay-event对应的值
            var id = data["id"];
            if (layEvent == "dataTable_edit") {
                jmdf.form("chooseBuyPersonForm?buyHousePersonId=" + id + "&contractId=" + ${(contract.id)!"0"});
            } else if (layEvent == "dataTable_delete") {
                jmdf.del("delBuyHousePersonById?buyHousePersonId=" + id);
            }
        });

        function setBuyHousePersonData() {
            var json = table.checkStatus(tableRenderId);

            var data = [];
            for (var i = 0; i < json.data.length; i++) {
                data.push(json.data[i].id);
            }
            var content = "";
            if (json.data.length == 0) {
                content = "确定该户被征收人为产权人吗？";
            } else if (json.data.length > 0) {
                content = "确认设置所选的【" + json.data.length + "】人为产权人吗？"
            }
            layer.open({
                title: false, shade: 0.5, content: content, btn: ['确定', '取消'], closeBtn: 0, btnAlign: 'c'
                , yes: function (index) {
                    $.get("setBuyHousePersonData", {
                        ids: data.toString(),
                        houseId:${houseId},
                        carLotId:${carLotId},
                        storageRoomId:${storageRoomId},
                        shopHouseId:${shopHouseId},
                    }, function (data) {
                        if (data.code == "0001") {//成功
                            parent.location.reload();
                        } else {//失败
                            layer.msg(data.message, {anim: 6, icon: 2, time: 3000});
                        }
                        layer.close(index);
                    });
                }
            });
        }
    });
</script>
</body>
</html>